<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll" />
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keyup.enter="enterFn"
      v-model="todoName"
    />
  </header>
</template>
 
<script>
export default {
  data() {
    return {
      todoName: "", // 任务名
    }
  },
  methods: {
    enterFn() {
      if (this.todoName.trim().length === 0) {
        return alert("请输入任务名")
      }
      this.$emit("addEvent", this.todoName);
      this.todoName = ""
    },
  },
  props: ["arr"],
  computed: {
    isAll: {
      set(val) {
        this.$emit("complateEvent", val)
      },
      get() {
        return this.arr.every((obj) => obj.isDone === true)
      },
    },
  },
};
</script>